/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.mvc.views
{
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class TextView extends View
	{
		private var _field:TextField = new TextField();
		private var _format:TextFormat = new TextFormat();
		private var _text:String;
		public function TextView(text:String)
		{
			_text = text;
			_field.type = TextFieldType.DYNAMIC;
			_format.font = _field.defaultTextFormat.font;
			_format.size = _field.defaultTextFormat.size;
			_format.color = _field.defaultTextFormat.color;
			_format.leading = _field.defaultTextFormat.leading;
			//_format.bold = true;
			super();
		}

		/**
		 * font name
		 */
		public function set font(value:String):void {
			_format.font = value;
		}
		
		/**
		 * font color
		 */
		public function set fontColor(rgb:uint):void {
			_format.color = rgb;
		}
		
		/**
		 * font size
		 */
		public function set fontSize(value:int):void {
			_format.size =value;
		}

		public function set leading(value:int):void {
			_format.leading = value;
		}
		
		public function formatClone():TextFormat {
			return new TextFormat(_format.font,
								  _format.size,
								  _format.color,
								  _format.bold,
								  _format.italic,
								  _format.underline,
								  _format.url,
								  _format.target,
								  _format.align,
								  _format.leftMargin,
								  _format.rightMargin,
								  _format.indent,
								  _format.leading);
		}
		override public function set width(value:Number):void {
			_field.width = value;
			super.width = value;
		}

		override protected function setup():void {
			addChild(_field);
		}	

		override public function beforeReady():void {
			_field.selectable = false;
            _field.defaultTextFormat = _format;
            _field.embedFonts = false;
			_field.text = _text;
			width = _field.textWidth+10;
			_field.height = _field.textHeight+10;
		}

	
		public function get field():TextField {
			return _field;
		}
		
		public function get text():String {
//			_text = _field.text;
			return _text;
		}
		public function set text(value:String):void {
			_text = value;
		}
	}
}